stage.set_background("space")
sprite = codesters.Sprite("spaceship")
sprite.set_size(0.5)
sprite.go_to(-200, 0)
stage.set_gravity(10)
stage.disable_all_walls()
def space_bar():
sprite.jump(5)
# add other actions...
stage.event_key("space", space_bar)
def interval():
top_height = random.randint(50, 300)
# sprite = codesters.Sprite("image", x, y)
top_rock = codesters.Sprite("asteroid", 0, 0)
top_rock.set_height(top_height)
top_rock.set_gravity_off()
top_rock.set_y_speed(0)
top_rock.set_top(250)
bot_height = 350 - top_height
# add any other actions...
stage.event_interval(interval, 2)
t = codesters.Teacher()
try:
params = t.find_function("Sprite")
tval1 = t.get_indent_at_line(params[2][0])
tval2 = params[2][1]
except:
tval1 = "DNE"
tval2 = "DNE"
try:
params = t.find_text("bot_rock")
tval3 = t.get_indent_at_line(params[0][0])
tval4 = params[0][1]
except:
params = "DNE"
tval3 = "DNE"
tval4 = "DNE"
try:
heights = t.find_function('set_height')
tval5 = t.get_indent_at_line(heights[1][0])
tval6 = heights[1][1]
except:
params = "DNE"
tval5 = "DNE"
tval6 = "DNE"
#print(tval1)
tester = TestManager()
t1 = TestObjective()
t1.add_success(tval1 == 4 and "codesters.Sprite" in tval2 and '"asteroid"' in tval2, "Great job!")
t1.add_failure(tval1 == "DNE", "Did you add another Sprite at Position?")
t1.add_failure(tval1 == 0, "Your asteroid should be indented four spaces inside the interval event")
t2 = TestObjective()
t2.add_success(tval4 != "DNE" and tval3 == 4, "Great job!")
t2.add_failure(tval4 == "DNE" or params == [], "Did you change the name of your new sprite?")
t2.add_failure(tval3 != 4, "Did you unindent your asteroid? It needs to be indented four spaces.")
t3 = TestObjective()
t3.add_success("bot_rock.set" in tval6 and '(bot_height)' in tval6 and tval5 == 4, "Great job!")
t3.add_failure(tval6 == "DNE", "Did you add a Set Height command?")
t3.add_failure('bot_rock.set' not in tval6, "Did you change the name in front of your Set Height command to bot_rock?")
t3.add_failure("(bot_height)" not in tval6, "Did you use the variable bot_height to set bot_rock's height?")
t3.add_failure(tval5 != 4, "Did you indent you Set Height command 4 spaces?")
# print params
tester.add_test_list([t1, t2, t3])
tester.run_tests()
tester.display_first_feedback()
# print params
# print tval2, tval1
-
Run Code
-
Activity Submitted!
提交作品
-
下个活动
-
Stop Running Code
-
Show Chart
-
Show Console
-
Reset Code Editor
-
Codesters How To (opens in a new tab)